<?php

class CCategoryController extends CController {
	
	public function __construct() {
		parent::__construct();
	}
	
	public function index() {
		$categories = CSingle::getInstance('CCategoryModel', 'getCategories');
		$this->_view->set('categories', $categories);
		$this->_view->display();
	}
	
	public function edit() {
		$this->_view->set('category', $this->_model->find($_GET['cat_id']));
		$this->_view->display();
	}
	
	public function update() {
		$this->_model->save($_POST);
		$this->message('更新成功', 0, $this->url('category'));
	}
	
	public function delete() {
		$this->_model->delete($_GET['cat_id']);
	}

	public function add() {
		$this->_view->display();
	}
	
	public function insert() {
		$this->_model->create($_POST);
		$this->message('添加成功', 0, $this->url('category'));
	}
}
